package com.twu.biblioteca.domain;

/**
 * Created by mnewman on 30/07/2014.
 */
public class User {
    public final String userID;
    public final String password;
    public final String email;
    public final String phone;
    public final String name;

    public User(String userID, String name, String password, String email, String phone) {
        this.userID = userID;
        this.password = password;
        this.email = email;
        this.phone = phone;
        this.name = name;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        User user = (User) o;

        if (email != null ? !email.equals(user.email) : user.email != null) return false;
        if (name != null ? !name.equals(user.name) : user.name != null) return false;
        if (password != null ? !password.equals(user.password) : user.password != null) return false;
        if (phone != null ? !phone.equals(user.phone) : user.phone != null) return false;
        if (userID != null ? !userID.equals(user.userID) : user.userID != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = userID != null ? userID.hashCode() : 0;
        result = 31 * result + (password != null ? password.hashCode() : 0);
        result = 31 * result + (email != null ? email.hashCode() : 0);
        result = 31 * result + (phone != null ? phone.hashCode() : 0);
        result = 31 * result + (name != null ? name.hashCode() : 0);
        return result;
    }

    public String toFormattedString() {
        return String.format("Name: %s, Email address: %s, Phone number: %s",
                this.name, this.email, this.phone);
    }
}
